#pragma once
#include "asynlog.h"
#include <mutex>
#include <vector>
#include <condition_variable>

namespace myutil {
    class RingBuffer;
}

namespace asynlog {
    class Logger;
    class LogContext {
        friend class LogImpl;
    public:
        LogContext(); 
        ~LogContext();
        Logger* GetLogger();
        void WriteLog(const std::string& log);
    private:
        void Close();
    private:
        LogConfig config_;
        FILE* pf_{ nullptr };
        std::vector<Logger*> loggers_;
        std::mutex mut_loggers_;
#if ASYN_LOG
        myutil::RingBuffer* buffer_{ nullptr };
        std::condition_variable condition_;
        std::mutex mut_condition_;
        std::thread thread_write_file_;
        std::atomic<bool> thread_stop_{ false };
        std::string ring_buffer_str_;
#endif
    };
}
